<template>
  <div>
    <el-select
      style="width: 100%"
      v-model="skuIdTmp"
      filterable
      clearable
      placeholder="输入商品名称搜索"
      @input="(val) => { $emit('input', val) }"
      :loading="loading">
      <el-option
        v-for="item in skuList"
        :key="item.id"
        :label="item.name"
        :value="item.id">
      </el-option>
    </el-select>
  </div>
</template>

<script>

import {skuList} from "@/api/product/sku";

export default {
  name: 'skuSelect',
  props: {
    value: String,
  },
  data() {
    return {
      skuList: [],
      loading: false,
      skuIdTmp: this.value
    };
  },
  computed: {},
  watch: {
    skuIdTmp(val) {
      this.$emit('input', val)
    },
    value(val) {
      this.skuIdTmp = val
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData() {
      this.loading = true
      skuList().then(res => {
        if (res.success) {
          this.skuList = res.data;
        }
      }).finally(() => {
        this.loading = false
      })
    }
  },
  model: {
    prop: 'value',
    event: 'input'
  }
};
</script>
